package monitor;

import java.util.ArrayList;

import stateMachine.StateMachine.Ball;

public class TrackingMonitor {
	double[] referenceArray;
	double[] controlSignalArray;
	ArrayList<double[]> weight = new ArrayList<double[]>();
	ArrayList<Double> mean = new ArrayList<Double>();
	private int counter;
	double meanRefBigBall = -4.401236868021578;
	double meanRefMediumBigBall = -1.9591867753061467;
	double meanRefSmallBall = -0.780460537064596;
	double tolerance = 0.75;
	
	public TrackingMonitor(){
		counter = 0;
		referenceArray = new double[1000];
		controlSignalArray = new double[1000];
	}



	public Ball determineBallSize() {
        double meanVal = 0;
        counter = 0;
        
        //Calculating mean value of U
        for (int i = 0; i < controlSignalArray.length; i++) {
                meanVal = meanVal + controlSignalArray[i];
        }
        meanVal = meanVal/controlSignalArray.length;
        
        System.out.print("MEAN VALUE" + meanVal);
        weight.add(controlSignalArray);
        mean.add(meanVal);
        controlSignalArray = new double[1000];
        
        /*
         * Return Cases.
         */
        
        if (inBetween(meanVal, meanRefBigBall, tolerance)) {
                return Ball.LARGE;
        } else if (inBetween(meanVal, meanRefMediumBigBall, tolerance)){
            return Ball.MEDIUM;
        } else if (inBetween(meanVal, meanRefSmallBall, tolerance)){
                return Ball.SMALL;
        } else {
                return Ball.UNKNOWNBALL;
        }
	}

private boolean inBetween(double value, double meanVal, double tolerance){
    return (value >= meanVal-tolerance && value <= meanVal+tolerance);
}


	public ArrayList<double[]> getWeightM(){
		return weight;
		
	}
	
	public ArrayList<Double> getMean(){
		return mean;
	}
	public boolean trackingArrayFilled() {
		return counter >= controlSignalArray.length ? true:false;
	}
		

	public double getRef() {
		return -6.8;
	}


	public void addUValue(double u) {
		if(counter < controlSignalArray.length-1 ){
			controlSignalArray[counter] = u;
			
			}
		counter = counter+1;
		}


}
